package com.southwind;

import java.util.Random;

/**
 * @author south wind
 * @version 1.0
 * @date 2025/3/18 11:52
 * @description
 */
public class OOPDemo2 {
    public static void main1(String[] args) {
        Rectangle rectangle = new Rectangle();

        rectangle.setchang(4);
        rectangle.setkuan(2);

        System.out.println("矩形的长是："+rectangle.getchang());
        System.out.println("矩形的长是："+rectangle.getkuan());

        rectangle.getInfo();




        }


    public static void main(String[] args) {
        Rectangle[] rectangles = new Rectangle[5];
        Random random = new Random();
        for (int i = 0; i < 5; i++) {
            double chang = 1+random.nextDouble()*9;//[1,10.0)的随机值
            double kuan = 1+random.nextDouble()*9;
            rectangles[i] = new Rectangle(chang ,kuan);
        }

        System.out.println("排序前的矩形信息：");
        for (Rectangle rectangle : rectangles) {
            System.out.println(rectangle.getInfo());
        }

        System.out.println("--------------------------------");

        for (int i = 0; i < rectangles.length - 1; i++) {
            for (int j = 0; j < rectangles.length-1; j++) {
               if (rectangles[j].getArea() > rectangles[j+1].getArea() ){
                   Rectangle temp =rectangles[j];
                   rectangles[j] = rectangles[j+1];
                   rectangles[j+1] = temp;
               }
            }
        }
        System.out.println("--------------------------------");
        System.out.println("排序后的矩形信息：");
        for (Rectangle rectangle : rectangles) {
            System.out.println(rectangle.getInfo());
        }
    }


    }

